package com.ymatou.iapi.livebuyer.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.QueryOrderProductInLiveSaleBean;
import com.ymatou.iapi.livebuyer.service.QueryOrderProductInLiveSaleCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;
/**
*查询订单商品是否为直播期间销售
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryOrderProductInLiveSale{
	private static QueryOrderProductInLiveSaleBean queryorderproductinlivesaleBean;
	private static QueryOrderProductInLiveSaleCall queryorderproductinlivesaleCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询订单商品是否为直播期间销售");
	}

	@Before
	public void caseUp() {
		queryorderproductinlivesaleBean=new QueryOrderProductInLiveSaleBean();
		queryorderproductinlivesaleCall=new QueryOrderProductInLiveSaleCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(queryorderproductinlivesaleCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryOrderProductInLiveSale_001() {
		Logger.start(true,"查询订单商品是否为直播期间销售,成功-是直播期间销售-历史直播");
		try {
			int userid=1;
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.enterGroup(createlive.getId(), userid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add(pid);
			LiveRoomCallService.AutoCloseLiveRoomByUserId( createlive.getUserId());
			String payTime=YMTDateUtil.getBeforeOrNextDay(0);
			queryorderproductinlivesaleBean.setPayTime(payTime);
			queryorderproductinlivesaleBean.setProductIds(productIds);
			queryorderproductinlivesaleBean.setSellerId(sellerId);
			queryorderproductinlivesaleBean.setUserId(userid);
			queryorderproductinlivesaleCall.setData(queryorderproductinlivesaleBean);
			queryorderproductinlivesaleCall.callService();			
			Logger.verifyEquals("200", queryorderproductinlivesaleCall.getString("code"), "验证code");
			List<String> salepids=new ArrayList<>();
			queryorderproductinlivesaleCall.getJsonObject().get("data").getAsJsonArray().forEach(p->salepids.add(p.getAsJsonObject().get("productId").getAsString()));
			productIds.forEach(pid1->{
				Logger.verifyEquals(true, salepids.contains(pid1), "验证数据包含");
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryOrderProductInLiveSale_002() {
		Logger.start(true,"不输入userId失败");
		try {
			int userid=2;
//			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
//			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
//			Logger.comment("创建商品：" + pid);
//			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
//			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
//			LiveRoomCallService.enterGroup(createlive.getId(), userid);
//			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add("p1");
			String payTime=YMTDateUtil.getBeforeOrNextDay(0);
			queryorderproductinlivesaleBean.setPayTime(payTime);
			queryorderproductinlivesaleBean.setProductIds(productIds);
			queryorderproductinlivesaleBean.setSellerId(sellerId);
//			queryorderproductinlivesaleBean.setUserId(userid);
			queryorderproductinlivesaleCall.setData(queryorderproductinlivesaleBean);
			queryorderproductinlivesaleCall.callService();			
			Logger.verifyEquals("100", queryorderproductinlivesaleCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryOrderProductInLiveSale_003() {
		Logger.start(true,"不输入sellerId失败");
		try {
			int userid=2;
//			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
//			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
//			Logger.comment("创建商品：" + pid);
//			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
//			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
//			LiveRoomCallService.enterGroup(createlive.getId(), userid);
//			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add("p1");
			String payTime=YMTDateUtil.getBeforeOrNextDay(0);
			queryorderproductinlivesaleBean.setPayTime(payTime);
			queryorderproductinlivesaleBean.setProductIds(productIds);
//			queryorderproductinlivesaleBean.setSellerId(sellerId);
			queryorderproductinlivesaleBean.setUserId(userid);
			queryorderproductinlivesaleCall.setData(queryorderproductinlivesaleBean);
			queryorderproductinlivesaleCall.callService();			
			Logger.verifyEquals("100", queryorderproductinlivesaleCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryOrderProductInLiveSale_004() {
		Logger.start(true,"不输入payTime失败");
		try {
			int userid=2;
//			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
//			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
//			Logger.comment("创建商品：" + pid);
//			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
//			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
//			LiveRoomCallService.enterGroup(createlive.getId(), userid);
//			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add("p1");
			String payTime=YMTDateUtil.getBeforeOrNextDay(0);
//			queryorderproductinlivesaleBean.setPayTime(payTime);
			queryorderproductinlivesaleBean.setProductIds(productIds);
			queryorderproductinlivesaleBean.setSellerId(sellerId);
			queryorderproductinlivesaleBean.setUserId(userid);
			queryorderproductinlivesaleCall.setData(queryorderproductinlivesaleBean);
			queryorderproductinlivesaleCall.callService();			
			Logger.verifyEquals("100", queryorderproductinlivesaleCall.getString("code"), "验证code");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryOrderProductInLiveSale_005() {
		Logger.start(true,"不输入productIds失败");
		try {
			int userid=2;
//			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
//			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
//			Logger.comment("创建商品：" + pid);
//			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
//			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
//			LiveRoomCallService.enterGroup(createlive.getId(), userid);
//			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add("p1");
			String payTime=YMTDateUtil.getBeforeOrNextDay(0);
			queryorderproductinlivesaleBean.setPayTime(payTime);
//			queryorderproductinlivesaleBean.setProductIds(productIds);
			queryorderproductinlivesaleBean.setSellerId(sellerId);
			queryorderproductinlivesaleBean.setUserId(userid);
			queryorderproductinlivesaleCall.setData(queryorderproductinlivesaleBean);
			queryorderproductinlivesaleCall.callService();			
			Logger.verifyEquals("100", queryorderproductinlivesaleCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryOrderProductInLiveSale_006() {
		Logger.start(true,"商家最近没有开过直播,不是直播销售-直播没有上线");
		try {
			int userid=6;
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.enterGroup(createlive.getId(), userid);
//			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add(pid);
			LiveRoomCallService.AutoCloseLiveRoomByUserId( createlive.getUserId());
			String payTime=YMTDateUtil.getBeforeOrNextDay(0);
			queryorderproductinlivesaleBean.setPayTime(payTime);
			queryorderproductinlivesaleBean.setProductIds(productIds);
			queryorderproductinlivesaleBean.setSellerId(sellerId);
			queryorderproductinlivesaleBean.setUserId(userid);
			queryorderproductinlivesaleCall.setData(queryorderproductinlivesaleBean);
			queryorderproductinlivesaleCall.callService();			
			Logger.verifyEquals("200", queryorderproductinlivesaleCall.getString("code"), "验证code");
			List<String> salepids=new ArrayList<>();
			queryorderproductinlivesaleCall.getJsonObject().get("data").getAsJsonArray().forEach(p->salepids.add(p.getAsString()));
			Logger.verifyEquals(0, salepids.size(), "验证没有返回");
//			productIds.forEach(pid1->{
//				Logger.verifyEquals(true, salepids.contains(pid1), "验证数据包含");
//			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryOrderProductInLiveSale_007() {
		Logger.start(true,"支付时间不在买手的开播时间内,不是直播销售");
		try {
			int userid=7;
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.enterGroup(createlive.getId(), userid);
//			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add(pid);
			LiveRoomCallService.AutoCloseLiveRoomByUserId( createlive.getUserId());
			String payTime=YMTDateUtil.getBeforeOrNextDay(1);
			queryorderproductinlivesaleBean.setPayTime(payTime);
			queryorderproductinlivesaleBean.setProductIds(productIds);
			queryorderproductinlivesaleBean.setSellerId(sellerId);
			queryorderproductinlivesaleBean.setUserId(userid);
			queryorderproductinlivesaleCall.setData(queryorderproductinlivesaleBean);
			queryorderproductinlivesaleCall.callService();			
			Logger.verifyEquals("200", queryorderproductinlivesaleCall.getString("code"), "验证code");
			List<String> salepids=new ArrayList<>();
			queryorderproductinlivesaleCall.getJsonObject().get("data").getAsJsonArray().forEach(p->salepids.add(p.getAsString()));
			Logger.verifyEquals(0, salepids.size(), "验证没有返回");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryOrderProductInLiveSale_008() {
		Logger.start(true,"买家没有浏览过买手开的直播间,不是直播销售");
		try {
			int userid=6;
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
//			LiveRoomCallService.enterGroup(createlive.getId(), userid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add(pid);
			LiveRoomCallService.AutoCloseLiveRoomByUserId( createlive.getUserId());
			String payTime=YMTDateUtil.getBeforeOrNextDay(0);
			queryorderproductinlivesaleBean.setPayTime(payTime);
			queryorderproductinlivesaleBean.setProductIds(productIds);
			queryorderproductinlivesaleBean.setSellerId(sellerId);
			queryorderproductinlivesaleBean.setUserId(userid);
			queryorderproductinlivesaleCall.setData(queryorderproductinlivesaleBean);
			queryorderproductinlivesaleCall.callService();			
			Logger.verifyEquals("200", queryorderproductinlivesaleCall.getString("code"), "验证code");
			List<String> salepids=new ArrayList<>();
			queryorderproductinlivesaleCall.getJsonObject().get("data").getAsJsonArray().forEach(p->salepids.add(p.getAsString()));
			Logger.verifyEquals(0, salepids.size(), "验证没有返回");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryOrderProductInLiveSale_009() {
		Logger.start(true,"查询订单商品是否为直播期间销售,成功-是直播期间销售-当前直播");
		try {
			int userid=1;
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.enterGroup(createlive.getId(), userid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add(pid);
//			LiveRoomCallService.AutoCloseLiveRoomByUserId( createlive.getUserId());
			String payTime=YMTDateUtil.getBeforeOrNextDay(0);
			queryorderproductinlivesaleBean.setPayTime(payTime);
			queryorderproductinlivesaleBean.setProductIds(productIds);
			queryorderproductinlivesaleBean.setSellerId(sellerId);
			queryorderproductinlivesaleBean.setUserId(userid);
			queryorderproductinlivesaleCall.setData(queryorderproductinlivesaleBean);
			queryorderproductinlivesaleCall.callService();			
			Logger.verifyEquals("200", queryorderproductinlivesaleCall.getString("code"), "验证code");
			List<String> salepids=new ArrayList<>();
			queryorderproductinlivesaleCall.getJsonObject().get("data").getAsJsonArray().forEach(p->salepids.add(p.getAsJsonObject().get("productId").getAsString()));
			productIds.forEach(pid1->{
				Logger.verifyEquals(true, salepids.contains(pid1), "验证数据包含");
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryOrderProductInLiveSale_010() {
		Logger.start(true,"查询订单商品是否为直播期间销售,成功-是直播期间销售-历史直播-验证EndTime延期量");
		try {
			int userid=10;
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.enterGroup(createlive.getId(), userid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			List<String> productIds=new ArrayList<>();
			productIds.add(pid);
			LiveRoomCallService.AutoCloseLiveRoomByUserId( createlive.getUserId());
			String payTime=YMTDateUtil.getBeforeOrNextSecond(14*60);
			queryorderproductinlivesaleBean.setPayTime(payTime);
			queryorderproductinlivesaleBean.setProductIds(productIds);
			queryorderproductinlivesaleBean.setSellerId(sellerId);
			queryorderproductinlivesaleBean.setUserId(userid);
			queryorderproductinlivesaleCall.setData(queryorderproductinlivesaleBean);
			queryorderproductinlivesaleCall.callService();			
			Logger.verifyEquals("200", queryorderproductinlivesaleCall.getString("code"), "验证code");
			List<String> salepids=new ArrayList<>();
			queryorderproductinlivesaleCall.getJsonObject().get("data").getAsJsonArray().forEach(p->salepids.add(p.getAsJsonObject().get("productId").getAsString()));
			productIds.forEach(pid1->{
				Logger.verifyEquals(true, salepids.contains(pid1), "验证数据包含");
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryOrderProductInLiveSale_011() {
		Logger.start(true,"查询订单商品是否为直播期间销售,成功-是直播期间销售-当前直播时间超出了预计结束时间");
		try {
			int userid=1;
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.enterGroup(createlive.getId(), userid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			new LiveRoomWapper().updateLiveRoomTime(YMTDateUtil.getBeforeOrNextSecond(-2*60*60), YMTDateUtil.getBeforeOrNextSecond(-1*60*60),YMTDateUtil.getBeforeOrNextMunite(-61),createlive.getId());

			List<String> productIds=new ArrayList<>();
			productIds.add(pid);
//			LiveRoomCallService.AutoCloseLiveRoomByUserId( createlive.getUserId());
			String payTime=YMTDateUtil.getBeforeOrNextDay(0);
			queryorderproductinlivesaleBean.setPayTime(payTime);
			queryorderproductinlivesaleBean.setProductIds(productIds);
			queryorderproductinlivesaleBean.setSellerId(sellerId);
			queryorderproductinlivesaleBean.setUserId(userid);
			queryorderproductinlivesaleCall.setData(queryorderproductinlivesaleBean);
			queryorderproductinlivesaleCall.callService();			
			Logger.verifyEquals("200", queryorderproductinlivesaleCall.getString("code"), "验证code");
			List<String> salepids=new ArrayList<>();
			queryorderproductinlivesaleCall.getJsonObject().get("data").getAsJsonArray().forEach(p->salepids.add(p.getAsJsonObject().get("productId").getAsString()));
			productIds.forEach(pid1->{
				Logger.verifyEquals(true, salepids.contains(pid1), "验证数据包含");
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}